#define _CRT_SECURE_NO_WARNINGS

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

void slove()
{
    int n, k;
    cin >> n >> k;
    vector<int> ret(n);
    vector<int> p;
    for (int i = 0; i < n; i++) cin >> ret[i];

    long long sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum += ret[i];
        if (ret[i] < 0) p.push_back(-ret[i]);
    }

    long long ans = 0, t = 0;
    int i = 0, j = 0;
    while (j < p.size())
    {
        t += p[j];
        if (j - i + 1 == k)
        {
            ans = max(ans, t);
            t -= p[i++];
        }
        j++;
    }
    cout << ans + sum << '\n';
}

int main()
{
    int t;
    cin >> t;
    while (t--) slove();

    return 0;
}